package com.softeem.ossmusic.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.softeem.ossmusic.comm.R;
import com.softeem.ossmusic.entity.Album;
import com.softeem.ossmusic.service.AlbumService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 专辑管理：专辑列表、专辑详情、专辑添加、专辑修改、专辑删除
 */
@Tag(name = "专辑管理")
@RestController
public class AlbumController {

    @Autowired
    private AlbumService albumService;

    @Operation(summary = "专辑列表", description = "分页查询专辑列表")
    @Parameters({
            @Parameter(name = "page", description = "当前页码", required = true),
            @Parameter(name = "limit", description = "每页记录数", required = true)
    })
    @GetMapping("/album/list")
    public R list(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "5")Integer limit) {
        //创建分页对象
        IPage<Album> ipage = new Page<Album>(page, limit);
        //执行查询(分页)  select * from album limit ?,?
        List<Album> list = albumService.list(ipage);
        //返回结果
        return R.success().setData(list);
    }

    @Operation(summary = "所有专辑", description = "查询所有专辑列表")
    @GetMapping("/album/listAll")
    public R list(){
        return R.success().setData(albumService.list());
    }

}
